#!/bin/sh
#
# Copyright 2008 Mattias Norrby
#
# This file is part of Test Dept..
#
# Test Dept. is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Test Dept. is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Test Dept..  If not, see <http://www.gnu.org/licenses/>.

OBJECT_FILE="$1"
POSSIBLE_STUBS="${2:-no_stubs}"

if [ "$POSSIBLE_STUBS" = "no_stubs" ]; then
  exit 0
fi

for symbol in `nm $OBJECT_FILE | sed -n '/test_dept.*set/s/.*test_dept_\(.*\)_set$/\1/p'`; do
  sed -n "/[^A-Za-z_*0-9]${symbol}[ ]*(/p; /^#include/p; " $POSSIBLE_STUBS
done | `dirname $0`/build_stub
